package com.ty.controller;

import cn.hutool.core.bean.BeanUtil;
import com.ty.bean.Loan;
import com.ty.common.bean.PageBean;
import com.ty.common.bean.ResultBean;
import com.ty.common.controller.BaseController;
import com.ty.query.LoanCustomerQuery;
import com.ty.service.LoanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Api(tags = "贷款管理")
@RequestMapping("/api")
public class LoanController extends BaseController {

    @Autowired
    LoanService loanService;

    @PostMapping("/loan")
    @ApiOperation("保存贷款客户")
    public ResultBean save( @RequestBody Loan loan) {
        int rs = loanService.save(loan);
        return saveResult(rs);
    }

    @ApiOperation("查询贷款客户列表")
    @PostMapping("/loan/list")
    public ResultBean<PageBean<List<Loan>>> query (@RequestBody LoanCustomerQuery query){
        PageBean bean = loanService.queryByMap((LoanCustomerQuery) BeanUtil.beanToMap(query));
        return success("贷款客户列表", bean);
    }


}
